import {
	defineStore
} from 'pinia'
import {
	preWithdrawalApi,
	withdrawalApplyApi,
	withdrawalRecordApi,
	commissionBillListApi,
	agentEnterApplyListBankApi,
	agentEnterStateApi,
	agentEnterApplyApi,
} from '@/pagesG/api/withdrawal.js'

export const useWithdrawStore = defineStore('withdraw', {
	state: () => {
		return {
			commissionAmt: 0, //可提佣金
			dayEstimateAmt: 0, // 今日预估佣金
			description: '', // 提现说明
			monthEstimateAmt: 0, // 本月预估佣金
			totalSettleAmt: 0, // 累计佣金
			bankList: [], // 已绑定银行卡
			agentEnterState: '', // 经纪人角色入驻状态
			signUrl: '', // 签约地址；短信签约模式，该字段为接收短信的手机号（脱敏）
			refuseReason: '', // 审核拒绝原因
		}
	},
	actions: {
		async getInfo() {
			const res = await preWithdrawalApi()
			this.commissionAmt = res.commissionAmt
			this.dayEstimateAmt = res.dayEstimateAmt
			this.description = res.description
			this.monthEstimateAmt = res.monthEstimateAmt
			this.totalSettleAmt = res.totalSettleAmt
			return res
		},
		async withdrawalApply(params) {
			const res = await withdrawalApplyApi(params)
			return res
		},
		async getRecordList(params) {
			const res = await withdrawalRecordApi(params)
			return res
		},
		async getCommissionBillList(params) {
			const res = await commissionBillListApi(params)
			return res
		},
		// 经纪人已签约的银行卡列表
		async getAgentEnterApplyListBank(params) {
			const res = await agentEnterApplyListBankApi(params)
			this.bankList = res || []
			return res
		},
		// 获取经纪人入驻状态 状态(1-待入驻，2-入驻失败，3-待签约，4-签约成功，5-签约失败，6-入驻审核中)
		async getAgentEnterState(params) {
			const res = await agentEnterStateApi(params)
			this.agentEnterState = res.state
			this.signUrl = res.signUrl
			this.refuseReason = res.refuseReason
			return res
		},
		// 经纪人入驻，绑定银行卡，并做签约
		async agentEnterApply(params) {
			const res = await agentEnterApplyApi(params)
			this.agentEnterState = res.state
			this.signUrl = res.signUrl
			this.refuseReason = res.refuseReason
			return res
		},
	}
})